package com.myc.train.member.controller;


import com.myc.train.common.resp.CommonResp;
import com.myc.train.member.req.MemberLoginReq;
import com.myc.train.member.req.MemberRequestReq;
import com.myc.train.member.req.MemberSendCodeReq;
import com.myc.train.member.resp.MemberLoginResp;
import com.myc.train.member.service.MemberService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    @GetMapping("/count")
    public CommonResp<Integer> count(){

        int count = memberService.count();
        CommonResp<Integer> resp = new CommonResp<>();
        resp.setContent(count);
        return resp;
    }

    @PostMapping("/register")
    public CommonResp<Long> register(@Valid MemberRequestReq req){

        Long register = memberService.register(req);
        CommonResp<Long> resp = new CommonResp<>();
        resp.setContent(register);
        return resp;
    }


    @PostMapping("/send-code")
    public CommonResp<Long> sendCode(@Valid @RequestBody MemberSendCodeReq req){
        memberService.sendCode(req);
        return new CommonResp<>();
    }



    @PostMapping("/login")
    public CommonResp<MemberLoginResp> Login(@Valid @RequestBody MemberLoginReq req){
        MemberLoginResp login = memberService.login(req);
        return new CommonResp<>(login);
    }
}
